﻿using GpuHud;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Profiling;

public abstract class StyleDataCollectionBase<T> : IDisposable where T : struct, StructDataTag
{
    public abstract int OnScreenArrayLength { get; }
    public abstract int OnScreenStyleCount { get; }
    public abstract int OffScreenStyleCount { get; }
    public abstract int TotalCount { get; }
    protected T Ttype;
    protected abstract Mesh m_RenderMesh { get; }
    protected List<GpuHudStyleDataAccessor<T>> m_PoolAccessors = new List<GpuHudStyleDataAccessor<T>>();

    protected readonly int m_BlockCount;
    protected readonly int m_blockTotal;
    protected int strideSize;

    protected bool currentFrameDirty = false;
    protected bool posDirty;


    public StyleDataCollectionBase(int stride, int blockCount = 1)
    {
        currentFrameDirty = false;
        posDirty = false;
        strideSize = stride;
        if (blockCount > 0)
        {
            m_BlockCount = blockCount;
            m_blockTotal = m_BlockCount * strideSize;
        }
    }

    public abstract void Dispose();

    public abstract void OnDestroy();

    #region 接口

    public int AddStyle(T data, GpuHudStyleDataAccessor<T> accessor)
    {
        var idx = OnAddStyleShaderData(data, accessor);
        m_PoolAccessors.Add(accessor);
        return idx;
    }
    protected abstract int OnAddStyleShaderData(T data, GpuHudStyleDataAccessor<T> accessor);

    public abstract void SetOnScreen(int idx);
    public abstract void SetOffScreen(int idx);

    public abstract void SetStyle(T data, int idx);

    public abstract T GetStyle(int idx);

    public abstract void SetPosition(int idx, float3 position);

    public abstract void SetColor(int idx, Color color);

    public abstract void SetScale(int idx, float scale);
    public abstract void SetAlpha(int idx, float alpha);
    public abstract void InitialShaderData(int idx);
    public abstract void Draw(Material material, Texture texture, bool guiDraw);
    #endregion


}
